home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
self
/
contrib.lha
/
contrib
/
SelfNews
/
wireI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-24
|
12KB
|
518 lines
/* File wireI.C
* created by Ian Wilkinson on Thu Sep 10 16:15:30 1992
*
* Copyright (c) Canon Research Centre Europe, 1992.
* All rights reserved.
*/
#include <_glueDefs.c.incl>
#include <NeWS/psio.h>
#include <wire/wire.h>
#include <jot/jot.h>
#include "wireIPS.h"
// From unixPrims.h.
extern fd_set activeFDs; // active file descriptors
char *WireSeal = "wire_Wire";
char *JotViewSeal = "JotView";
char *JotTextSeal = "JotText";
char *JotRulerSeal = "JotRuler";
#define toCntl( c ) (c & 037)
void
kybdManager( JotView *jotView, char ch )
{
if (JotView_ReadOnly(jotView) == FALSE) {
JotText *jotText;
int caretPosn;
jotText = JotView_Text(jotView);
caretPosn = JotText_Caret(jotText);
switch (ch) {
case toCntl('D'):
case '\177':
(void)JotText_DeleteCharacters(jotText, caretPosn, (ch == toCntl('D')) ?
1 : -1);
break;
case '\r':
ch = '\n';
default:
JotText_InsertCharacters(jotText, caretPosn, &ch, 1);
break;
}
JotView_EnsurePositionVisible(jotView, JotText_Caret(jotText));
}
}
int
jotInitialize( int w )
{
Jot_Initialize((wire_Wire)w);
return 1;
}
JotText *
newJotText( int initialSz )
{
return JotText_New(initialSz);
}
int
placeAtEnd( char *text, JotText *jotText, void *FH )
{
int nChars;
JotView *jotView;
nChars = JotText_Characters(jotText);
if (JotText_InsertString(jotText, nChars, text) == -1) {
failure(FH, "JotText_InsertString");
return 0;
}
if ((jotView = JotText_FirstView(jotText)) == 0) {
failure(FH, "JotText_FirstView");
return 0;
}
JotView_Update(jotView);
return 1;
}
JotView *
newJotView( JotText *jotText, int isCanvasReqd, int w, void *FH )
{
JotView *jotView;
wire_SetCurrent(w);
jotView = JotView_New(jotText, (boolean)isCanvasReqd);
JotView_SetEventHandlers(jotView, Jot_KEYBOARD_EVENT, kybdManager, Jot_NULL_EVENT);
if (ps_flush_PostScript() == -1) {
failure(FH, "ps_flush_PostScript in newJotView");
return 0;
}
return jotView;
}
int
jotViewCanvas( JotView *jotView )
{
return JotView_Canvas(jotView);
}
int
jotViewSetReadOnly( int isProtected, JotView *jotView )
{
JotView_SetReadOnly(jotView, (boolean)isProtected);
return 1;
}
int
jotViewAspects( JotView *jotView )
{
int tk;
wire_Wire w;
tk = JotView_Canvas(jotView);
w = JotView_Wire(jotView);
wire_SetCurrent(w);
PSjotViewAspects(tk);
return wire_ReadInt();
}
int
jotViewBehaviour( JotView *jotView, int *behaviour )
{
int tk;
wire_Wire w;
int aspects;
tk = JotView_Canvas(jotView);
w = JotView_Wire(jotView);
wire_SetCurrent(w);
PSjotViewBehaviour(tk);
aspects = wire_ReadInt();
for (int i = 0; i < aspects; i++)
behaviour[i] = wire_ReadInt();
return 1;
}
int
jotViewRespond( JotView *jotView, void *FH )
{
wire_Wire jotViewW;
jotViewW = JotView_Wire(jotView);
wire_SetCurrent(jotViewW);
while (ps_check_input()) {
wire_Handler callback;
int tg;
if (ps_peek_tag(&tg) == 1) {
tg = wire_ReadTag();
callback = wire_TagProc(tg);
callback(tg, 0);
}
else {
break;
}
}
JotView_UpdateViews();
return 1;
}
JotRuler *
newJotRuler()
{
return JotRuler_New();
}
int
jotFontInitialize( JotRuler *ruler, JotView *jotView, JotText *jotText )
{
JotFont *font;
wire_Wire w;
w = JotView_Wire(jotView);
wire_SetCurrent(w);
JotView_SetPrinterMatchFonts(jotView, TRUE);
font = JotFont_New("LucidaSans");
JotRuler_SetParameters(ruler, Jot_FONT, font,
Jot_BOLD, FALSE,
Jot_FONT_SIZE, 10,
Jot_NULL_PARAMETER);
JotText_SetDefaultRuler(jotText, ruler);
return 1;
}
int
jotRulerSetParameter( JotRuler *ruler, int parameter, int value )
{
JotRuler_SetParameters(ruler, parameter, value, Jot_NULL_PARAMETER);
return 1;
}
int
jotRulerSetFont( JotRuler *ruler, char *fontName )
{
JotFont *font;
font = JotFont_New(fontName);
JotRuler_SetParameters(ruler, Jot_FONT, font, Jot_NULL_PARAMETER);
return 1;
}
int
jotRulerSetRulerName( JotRuler *ruler, char *rulerName )
{
JotRuler_SetParameters(ruler, Jot_RULER_NAME, rulerName, Jot_NULL_PARAMETER);
return 1;
}
int
jotViewUpdate( int w, JotView *jotView )
{
wire_SetCurrent(w);
JotView_Update(jotView);
return 1;
}
int
jotTextSize( JotText *jotText )
{
return JotText_Characters(jotText);
}
int
jotTextContentsInto( char *s, JotText *jotText, void *FH )
{
int jotTextSz;
JotSpan *jotSpan;
jotTextSz = JotText_Characters(jotText);
if ((jotSpan = JotSpan_New(jotText, 0, jotTextSz)) == 0) {
failure(FH, "...in jotTextContentsInto: JotSpan_New");
return 0;
}
if (JotSpan_Contents(jotSpan, s) == -1) {
failure(FH, "...in jotTextContentsInto: JotSpan_Contents");
return 0;
}
JotSpan_Free(jotSpan);
return 1;
}
int
wireAllocateTags( int w, int nTgs )
{
wire_SetCurrent((wire_Wire)w);
return wire_AllocateTags(nTgs);
}
int
wireAllocateTokens( int w, int nTks )
{
return wire_AllocateTokens((wire_Wire)w, nTks);
}
int
wireDeallocateToken( int w, int tk )
{
return wire_DeallocateTokens((wire_Wire)w, tk, 1);
}
int
wireClose( int w, void *FH )
{
if (wire_Close((wire_Wire)w) == FALSE) {
failure(FH, wire_ErrorString());
return 0;
}
return 1;
}
int
wireCurrent()
{
return wire_Current();
}
int
wireEnable( int w, void *FH )
{
if (wire_Enable((wire_Wire)w) == FALSE) {
failure(FH, wire_ErrorString());
return 0;
}
return 1;
}
char*
wireErrorString()
{
return wire_ErrorString();
}
int
wireInputFd( int w )
{
PSFILE *psiop;
psiop = wire_PSinput(w);
return psio_fileno(psiop);
}
int
wireOutputFd( int w )
{
PSFILE *psiop;
psiop = wire_PSoutput(w);
return psio_fileno(psiop);
}
int
wireOpen( char *display, void *FH )
{
wire_Wire w;
if ((w = wire_Open(display)) == wire_INVALID_WIRE) {
failure(FH, wire_ErrorString());
return 0;
}
FD_SET(wireOutputFd(w), &activeFDs);
return w;
}
int
wireReadTag( int w )
{
wire_SetCurrent((wire_Wire)w);
return wire_ReadTag();
}
int
wireReadInt( int w )
{
wire_SetCurrent((wire_Wire)w);
return wire_ReadInt();
}
char*
wireReadString( int w, char *aString )
{
wire_SetCurrent((wire_Wire)w);
return wire_ReadString(aString);
}
int
wireSetCurrent( int w, void *FH )
{
if (wire_SetCurrent((wire_Wire)w) == FALSE) {
failure(FH, wire_ErrorString());
return 0;
}
return 1;
}
int
wireSkipEvent( int w, void *FH )
{
wire_SetCurrent((wire_Wire)w);
if (wire_SkipEvent() == FALSE) {
failure(FH, wire_ErrorString());
return 0;
}
return 1;
}
int
wireValid( int w, void *FH )
{
if (wire_Valid((wire_Wire)w) == FALSE) {
failure(FH, wire_ErrorString());
return 0;
}
return 1;
}
int
wireWouldNotify( int w )
{
return wire_WouldNotify((wire_Wire)w);
}
int
wireInvalidWire()
{
return wire_INVALID_WIRE;
}
int
psLoadPackages( int w, void *FH )
{
wire_SetCurrent((wire_Wire)w);
PSloadPackages();
if (ps_flush_PostScript() == -1) {
failure(FH, "Problem with psLoadPackages");
return 0;
}
return 1;
}
int
psSend( int w, char *psFragment, void *FH )
{
wire_SetCurrent((wire_Wire)w);
PSsend(psFragment);
if (ps_flush_PostScript() == -1) {
failure(FH, "Problem with psSend");
return 0;
}
return 1;
}
int
psSendTo( int w, int tk, char *psFragment, void *FH )
{
wire_SetCurrent((wire_Wire)w);
PSsendTo(tk, psFragment);
if (ps_flush_PostScript() == -1) {
failure(FH, "Problem with psSendTo");
return 0;
}
return 1;
}
int
psSyncReply( int w, int tk, char *psFragment, void *FH )
{
wire_SetCurrent((wire_Wire)w);
PSsyncReply(tk, psFragment);
if (ps_flush_PostScript() == -1) {
failure(FH, "Problem with psSyncReply");
return 0;
}
return 1;
}
int
psFlushPostScript( int w, void *FH )
{
wire_SetCurrent((wire_Wire)w);
if (ps_flush_PostScript() == -1) {
failure(FH, "Problem with ps_flush_PostScript");
return 0;
}
return 1;
}
int
peekTag( int w, void *FH )
{
int isTg, tg;
wire_SetCurrent((wire_Wire)w);
if ((isTg = ps_peek_tag(&tg)) == -1) {
failure(FH, "Problem with ps_peek_tag");
return 0;
}
return (isTg ? tg : -1);
}
int
checkInput( int w, void *FH )
{
int isEmpty;
wire_SetCurrent((wire_Wire)w);
if ((isEmpty = ps_check_input()) == -1) {
failure(FH, "Problem with ps_check_input");
return 0;
}
return isEmpty;
}
#define WHAT_GLUE FUNCTIONS
C_func_2(int,, wireAllocateTags, allocateTagsGlue,, proxy, (int, WireSeal), int,)
C_func_2(int,, wireAllocateTokens, allocateTokensGlue,, proxy, (int, WireSeal), int,)
C_func_2(bool,, wireDeallocateToken, deallocateTokenGlue,, proxy, (int, WireSeal), int,)
C_func_1(bool,, wireClose, closeGlue, fail, proxy, (int, WireSeal))
C_func_0(int,, wireCurrent, currentGlue,)
C_func_1(bool,, wireEnable, enableGlue, fail, proxy, (int, WireSeal))
C_func_0(string,, wireErrorString, errorStringGlue,)
C_func_1(proxy, (int, WireSeal), wireOpen, openGlue, fail, string,)
C_func_1(int,, wireReadTag, readTagGlue,, proxy, (int, WireSeal))
C_func_1(int,, wireReadInt, readIntGlue,, proxy, (int, WireSeal))
C_func_2(string,, wireReadString, readStringGlue,, proxy, (int, WireSeal), string,)
C_func_1(bool,, wireSetCurrent, setCurrentGlue, fail, proxy, (int, WireSeal))
C_func_1(bool,, wireSkipEvent, skipEventGlue, fail, proxy, (int, WireSeal))
C_func_1(bool,, wireValid, validGlue, fail, proxy, (int, WireSeal))
C_func_1(bool,, wireWouldNotify, wouldNotifyGlue,, proxy, (int, WireSeal))
C_func_0(int,, wireInvalidWire, invalidWireGlue,)
C_func_1(int,, wireInputFd, wireInputFdGlue,, proxy, (int, WireSeal))
C_func_1(int,, wireOutputFd, wireOutputFdGlue,, proxy, (int, WireSeal))
C_func_1(int,, psLoadPackages, loadPackagesGlue, fail, proxy, (int, WireSeal))
C_func_2(int,, psSend, sendGlue, fail, proxy, (int, WireSeal), string,)
C_func_3(int,, psSendTo, sendToGlue, fail, proxy, (int, WireSeal), int,, string,)
C_func_3(int,, psSyncReply, syncReplyGlue, fail, proxy, (int, WireSeal), int,, string,)
C_func_1(int,, psFlushPostScript, flushPostScriptGlue, fail, proxy, (int, WireSeal))
C_func_1(int,, peekTag, peekTagGlue, fail, proxy, (int, WireSeal))
C_func_1(bool,, checkInput, checkInputGlue, fail, proxy, (int, WireSeal))
C_func_1(bool,, jotInitialize, jotInitializeGlue,, proxy, (int, WireSeal))
C_func_1(proxy_null, (JotText *, JotTextSeal), newJotText, newJotTextGlue,, int,)
C_func_3(proxy_null, (JotView *, JotViewSeal), newJotView, newJotViewGlue, fail,
proxy, (JotText *, JotTextSeal), bool,, proxy, (int, WireSeal))
C_func_2(bool,, placeAtEnd, placeAtEndGlue, fail, string,, proxy, (JotText *, JotTextSeal))
C_func_1(int,, jotTextSize, sizeGlue,, proxy, (JotText *, JotTextSeal))
C_func_2(bool,, jotTextContentsInto, contentsIntoGlue, fail,
bv, char *, proxy, (JotText *, JotTextSeal))
C_func_2(bool,, jotViewSetReadOnly, jotViewSetReadOnlyGlue,,
bool,, proxy, (JotView *, JotViewSeal))
C_func_1(int,, jotViewCanvas, jotViewCanvasGlue,, proxy, (JotView *, JotViewSeal))
C_func_1(int,, jotViewAspects, jotViewAspectsGlue,, proxy, (JotView *, JotViewSeal))
C_func_2(int,, jotViewBehaviour, jotViewBehaviourGlue,,
proxy, (JotView *, JotViewSeal), bv, int *)
C_func_1(bool,, jotViewRespond, jotViewRespondGlue, fail, proxy, (JotView *, JotViewSeal))
C_func_2(bool,, jotViewUpdate, jotViewUpdateGlue,, proxy, (int, WireSeal), proxy, (JotView *, JotViewSeal))
C_func_0(proxy_null, (JotRuler *, JotRulerSeal), newJotRuler, newJotRulerGlue,)
C_func_3(bool,, jotFontInitialize, jotFontInitializeGlue,,
proxy, (JotRuler *, JotRulerSeal),
proxy, (JotView *, JotViewSeal),
proxy, (JotText *, JotTextSeal))
C_func_3(bool,, jotRulerSetParameter, jotRulerSetParameterGlue,,
proxy, (JotRuler *, JotRulerSeal), int,, int,)
C_func_2(bool,, jotRulerSetFont, jotRulerSetFontGlue,,
proxy, (JotRuler *, JotRulerSeal), string,)
C_func_2(bool,, jotRulerSetRulerName, jotRulerSetRulerNameGlue,,
proxy, (JotRuler *, JotRulerSeal), string,)
#undef WHAT_GLUE